package com.android.boncen.commonFrame;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.support.v7.app.NotificationCompat;
import android.util.Log;

/**
 * 功能描述:
 *
 * @date 2017/2/8
 */

public class NotificationService extends Service {



    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {

        Log.i("NotificationService","onStartCommand");
        if (intent != null && "com.start.alarm".equals(intent.getAction()))
        {
            NotificationManager barmanager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            Intent startIntent = new Intent(this, MainActivity.class);// Constan
            startIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startIntent.putExtra("index",0);

            NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplication());
            Bitmap largeIcon = BitmapFactory.decodeResource(getResources(),R.drawable.blood_logo);
            builder.setLargeIcon(largeIcon);
            builder.setSmallIcon(R.drawable.blood_logo);
            builder.setContentTitle("开始记录血糖！");
            builder.setContentText("已经饭后两小时，赶紧记录血糖吧！");
            builder.setTicker("记录时间到！！！");
            builder.setContentIntent(PendingIntent.getActivity(this,0,startIntent,0));
            Notification notification = builder.getNotification();
            barmanager.notify(0,notification);
            // 提醒之后，修改提醒开关
            MyApplication.save(this,false);
        }

        return super.onStartCommand(intent, flags, startId);
    }
}
